/**
 * gbl
 * 主页界面js文件（加载信息）
 * 创建时间：9.19 16:38
 */

$(function () {
    var addFood = '/home/hotfood';
    var addAdvertise = '/home/advertise';
    var addStore = 'home/hotstore';
    getAdvertise();
    getHotFood();
    getHotStore();
    // 添加广告
    function getAdvertise() {
        $.getJSON(addAdvertise, function (data) {
            if (!data.success){
                //alert("内部测试")
                var advertiseHtml01 = '';
                var advertiseHtml02 = '';
                var advertiseHtml03 = '';
                data.advertiseList.map(function (item,index) {
                    if (index == 0){
                        advertiseHtml01 += '<a href="storeInfo.html?storeId=' + item.storeId + '" onclick="advertiseOnClick()" target="_blank">\n' +
                            '                       <img src="' + item.homeImg + '" style="height: 320px; width:100%" alt="...">\n' +
                            '                        <div class="carousel-caption">\n' +
                            '                            <h3>' + item.homeName + '</h3>\n' +
                            '                            <p>' + item.homeDescribe + '</p>\n' +
                            '                        </div>\n' +
                            '                    </a>';
                    } else if (index == 1){
                        advertiseHtml02 += '<a href="storeInfo.html?storeId=' + item.storeId + '" onclick="advertiseOnClick()" target="_blank">\n' +
                            '                       <img src="' + item.homeImg + '" style="height: 320px; width:100%" alt="...">\n' +
                            '                        <div class="carousel-caption">\n' +
                            '                            <h3>' + item.homeName + '</h3>\n' +
                            '                            <p>' + item.homeDescribe + '</p>\n' +
                            '                        </div>\n' +
                            '                    </a>';
                    } else if (index == 2){
                        advertiseHtml03 += '<a href="storeInfo.html?storeId=' + item.storeId + '" onclick="advertiseOnClick()" target="_blank">\n' +
                            '                        <img src="' + item.homeImg + '" style="height: 320px; width:100%" alt="...">\n' +
                            '                        <div class="carousel-caption">\n' +
                            '                            <h3>' + item.homeName + '</h3>\n' +
                            '                            <p>' + item.homeDescribe + '</p>\n' +
                            '                        </div>\n' +
                            '                    </a>';
                    }
                });
                $('#advertise01').html(advertiseHtml01);
                $('#advertise02').html(advertiseHtml02);
                $('#advertise03').html(advertiseHtml03);
            }
        });
    }
    // 添加热门食品
    function getHotFood() {
        $.getJSON(addFood,function (data){
            if (!data.success){
                var showInfo = '';
                var urlHref = '';
                data.hotFoodList.map(function (item,index) {
                    if (index == 0){
                        showInfo += '<div class="col-md-1-10" style="margin-bottom: 5px; height: 260px;">\n' +
                            '                            <a href="commodity.html?commodityId=' + item.commodityId + '">\n' +
                            '                            <img src="'+ item.picture + '" style="border-radius: 10px;">' +
                            '                            <div class="eats_list_info1" style="margin-bottom: 5px; text-decoration: none; height: 200px; border-radius: 10px; background-size: 100% 200px;">\n' +
                            '                              <span class="pull-left" style="margin-left: 15px; text-decoration: none; margin-top: 10px; font-weight: bold; ">' + item.commodityName + '</span>\n' +
                            '                              <span class="pull-right " style="margin-right: 10px; text-decoration: none; margin-top: 10px; ">￥:' + item.price + '</span>'+
                            '                            </div>\n' +
                            '                            </a>\n' +
                            '                        </div>';
                    } else {
                        showInfo += '<div class="col-md-1-5" style="height: 260px;">\n' +
                            '                            <a href="commodity.html?commodityId=' + item.commodityId + '">\n' +
                            '                            <img src="'+ item.picture + '" style="border-radius: 10px;">' +
                            '                            <div style="text-decoration: none; height: 30px; margin-top: 5px;">' +
                            '                             <span class="pull-left" style="margin-left: 15px; text-decoration: none; font-size: 18px; font-weight: bold;">' + item.commodityName + '</span>\n'+
                            '                             <span class="pull-right " style="margin-right: 10px; text-decoration: none; font-size: 18px; ">￥:' + item.price + '</span></div>\n' +
                            '                            <div style="text-decoration: none;height: 40px; overflow: hidden;">\n' +
                            '                                <p style="text-decoration: none; font-size: 15px; color: #999999; font-family: 等线;">' + item.commodityDescribe + '</p>\n' +
                            '                            </div>\n' +
                            '                            </a>\n' +
                            '                        </div>';
                    }
                });
                $('#hotfood').html(showInfo);
            }
        });
    }
    function getHotStore() {
        $.getJSON(addStore, function (data) {
            if (!data.success){
                var showInfo = '';
                data.hotStoreList.map(function (item,index) {
                    showInfo += '<li data-hotelid="50101461" class="h50101461">\n' +
                        '                            <a href="storeInfo.html?storeId=' + item.storeId + '" target="_blank">\n' +
                        '                                <img src="' + item.picture + '" title="' + item.storeName + '" class="img-rounded">\n' +
                        '                            </a>\n' +
                        '                        </li>';
                });
                $('#hotstore').html(showInfo);
            }
        });
    }

})